package cn.stylefeng.guns.modular.school.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.school.entity.ExamScore;
import cn.stylefeng.guns.modular.school.mapper.ExamScoreMapper;
import cn.stylefeng.guns.modular.school.model.params.ExamScoreParam;
import cn.stylefeng.guns.modular.school.model.result.ExamScoreResult;
import  cn.stylefeng.guns.modular.school.service.ExamScoreService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 考试成绩 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-12-03
 */
@Service
public class ExamScoreServiceImpl extends ServiceImpl<ExamScoreMapper, ExamScore> implements ExamScoreService {

    @Override
    public void add(ExamScoreParam param){
        ExamScore entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ExamScoreParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ExamScoreParam param){
        ExamScore oldEntity = getOldEntity(param);
        ExamScore newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ExamScoreResult findBySpec(ExamScoreParam param){
        return null;
    }

    @Override
    public List<ExamScoreResult> findListBySpec(ExamScoreParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ExamScoreParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<ExamScoreResult> findListByStudentId(ExamScoreParam param) {
        return this.baseMapper.customListByStudentId(param);
    }

    @Override
    public List<ExamScoreResult> findListByStudentIds(ExamScoreParam param) {
        return this.baseMapper.customListByStudentIds(param);
    }

    private Serializable getKey(ExamScoreParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ExamScore getOldEntity(ExamScoreParam param) {
        return this.getById(getKey(param));
    }

    private ExamScore getEntity(ExamScoreParam param) {
        ExamScore entity = new ExamScore();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
